/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package coms.action;

import coms.delegates.ConferenceDelegate;
import coms.delegates.ConferenceItemBookingDelegate;
import coms.delegates.ConferenceItemDelegate;
import coms.delegates.ConferenceRegistrationDelegate;
import coms.dto.*;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Pk
 */
public class ConferenceItemBookingAction extends ComsActionSupport {

    private List<ConferenceRegistration> registeredConference;
    private List<Conference> bookedConference;
    private String conference;
    private String item;
    private User user;
    private List<String> itemList = new ArrayList<String>();
    private String actionType;
    private String ConferenceBookingId;

    public String getConferenceBookingId() {
        return ConferenceBookingId;
    }

    public void setConferenceBookingId(String ConferenceBookingId) {
        this.ConferenceBookingId = ConferenceBookingId;
    }

    public String getActionType() {
        return actionType;
    }

    public void setActionType(String actionType) {
        this.actionType = actionType;
    }

    public List<String> getItemList() {
        return itemList;
    }

    public void setItemList(List<String> itemList) {
        this.itemList = itemList;
    }

    public ConferenceItemBookingAction() {
    }

    public String getConference() {
        return conference;
    }

    public void setConference(String conference) {
        this.conference = conference;
    }

    public String getItem() {
        return item;
    }

    public void setItem(String item) {
        this.item = item;
    }

    public String confirmBooking() {

        Map<String, Object> session = getSession();
        user = (User) session.get("user");
        ConferenceItemDelegate conItemDel = new ConferenceItemDelegate();
        if (!getItemList().isEmpty()) {
            ConferenceItemBookingDelegate conItemBookingDelegate = new ConferenceItemBookingDelegate();
            for (String conItemId : getItemList()) {
                ConferenceItem conItem = conItemDel.getById(Integer.parseInt(conItemId));
                ConferenceItemBooking conItemBooking = new ConferenceItemBooking();
                conItemBooking.setConferenceItem(conItem);
                conItemBooking.setParticipant(user);
                conItemBooking.setValid(true);
                conItemBookingDelegate.create(conItemBooking);
            }
            return SUCCESS;
        } else {
            return "error";
        }

    }

    public String cancelBooking() {
        try {
            System.out.println(ConferenceBookingId);
            Map<String, Object> session = getSession();
            user = (User) session.get("user");
            ConferenceItemBookingDelegate conItemBookingDelegate = new ConferenceItemBookingDelegate();
            ConferenceItemBooking c = conItemBookingDelegate.getById(Integer.parseInt(ConferenceBookingId));
            c.setValid(false);
            conItemBookingDelegate.update(c);
            return "unsubscribed";
        } catch (Exception e) {
            return "error";
        }
    }

    public String create() {
        actionType = "create";
        return "create";
    }

    public String delete() {
        actionType = "delete";
        return "create";
    }
}
